<?php
class Organization extends Controller {
    public function index() {
        $this->load->model("adminorg_model");
        $cat = $this->uri->segment(4);
        $orgArr = $this->adminorg_model->getOrgInfo($cat);
        if($cat == "religious")
        {
            $catLabel = "Religious Organizations";
        } else {
            $catLabel = "Organizations";
        }
        $data['orgArr'] = $orgArr;
        $data['catLabel'] = $catLabel;
        $data['cat'] = $cat;
        $this->template->load('admintemplate', 'organization/index', $data);
    }

    public function orgmember()
    {
        $this->load->model("adminorg_model");
        $memberArr = $this->adminorg_model->getOrgMembers();
        $data['memberArr'] = $memberArr;
        $this->template->load('admintemplate', 'organization/orgmembers', $data);
    }

    public function addorganization()
    {
        $this->load->model("adminorg_model");
        $cat_arr = $this->adminorg_model->getRelOrgCat();
        $data['cat_arr'] = $cat_arr;
        $this->template->load('admintemplate', 'organization/addorganization', $data);
    }

    public function doaddorganization()
    {
        $this->load->model("adminbranch_model");
        $add_org = $this->adminbranch_model->addOrganization($_POST);
        if($add_org)
        {
            $this->template->load('admintemplate', 'secu/organization/index');
        } else {
            $data['error_msg'] = "Error has occured while adding new organization. Please contact system administrator";
            $this->template->load('admintemplate', 'secu/organization/addbranch', $data);
        }
    }
    
    public function addmember()
    {
        $this->load->model("adminorg_model");
        $this->load->model("adminbranch_model");
        $data['cat_arr'] = $this->adminbranch_model->getOrgCat();
        $data['designation_arr'] = $this->adminbranch_model->getDesignations();
        $this->template->load('admintemplate', 'organization/addmember', $data);
    }

    public function doaddmember()
    {
        error_reporting(E_ALL);
        $this->load->model("adminorg_model");

        $add_member = $this->adminorg_model->addMember($_POST);
        if($add_member)
        {
            //$this->template->load('admintemplate', 'secu/organization/index');
            redirect('secu/organization/index', 'refresh');
        } else {
            $data['error_msg'] = "Error has occured while adding new member. Please contact system administrator";
            $this->template->load('admintemplate', 'secu/organization/addmember', $data);
        }
    }

    public function addreligiousorg()
    {
        $this->load->model("adminorg_model");
        $cat_arr = $this->adminorg_model->getRelOrgCat();
        $data['cat_arr'] = $cat_arr;
        $this->template->load('admintemplate', 'organization/addreligiousorg', $data);
    }

    public function doaddreligiousorg()
    {
        error_reporting(E_ALL);
        $this->load->model("adminorg_model");
        $add_org = $this->adminorg_model->addRelOrg($_POST);
        if($add_org)
        {
            //$this->template->load('admintemplate', 'secu/organization/index');
            redirect('secu/organization/index', 'refresh');
        } else {
            $data['error_msg'] = "Error has occured while adding new organization. Please contact system administrator";
            $this->template->load('admintemplate', 'secu/organization/addbranch', $data);
        }
    }

    public function addbranchorg()
    {
        $this->load->model("adminorg_model");
        $this->load->model("adminbranch_model");
        $data['cat_arr'] = $this->adminbranch_model->getOrgCat();
        $this->template->load('admintemplate', 'organization/addbranchorg', $data);
    }

    public function doaddbranchorg()
    {
        $this->load->model("adminorg_model");
        $add_org = $this->adminorg_model->addBranchOrg($_POST);
        if($add_org)
        {
            //$this->template->load('admintemplate', 'secu/organization/index');
            redirect('secu/organization/index', 'refresh');
        } else {
            $data['error_msg'] = "Error has occured while adding new organization. Please contact system administrator";
            $this->template->load('admintemplate', 'secu/organization/addbranch', $data);
        }
    }

    public function gallery()
    {
        $this->template->load('admintemplate', 'secu/organization/gallery');
    }

    public function addgallery()
    {
        $sect_id = $this->uri->segment(4);
        $sect = $this->uri->segment(5);
        $gallery_image_count = $this->config->item("gallery_image_count");
        $data['gallery_image_count'] = $gallery_image_count;
        $data['sect_id'] = $sect_id;
        $data['sect'] = $sect;
        $this->template->load('admintemplate', 'secu/organization/addgallery', $data);
    }

    public function doaddgallery()
    {
        error_reporting(E_ALL);
        $sect_id = $this->uri->segment(4);
        $sect = $this->uri->segment(5);
        $this->load->model("adminimage_model");

        $add_gallery = $this->adminimage_model->addGalleryImages($_FILES, $sect_id, $sect);

        if($add_gallery)
        {
            redirect('secu/organization/index/religious', 'refresh');
        }
    }
}
?>
